package com.usth.action;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.google.common.collect.Multimaps;
import com.opensymphony.xwork2.ActionSupport;
import com.usth.model.Roles;
import com.usth.model.User;
import com.usth.service.IUserService;

public class UserAction extends ActionSupport {
	private User user;
	private IUserService userservice;
	private String result;
	private List<User> ulist;
	private List<Roles> rolelist;
	
	public List<User> getUlist() {
		return ulist;
	}

	public void setUlist(List<User> ulist) {
		this.ulist = ulist;
	}

	public List<Roles> getRolelist() {
		return rolelist;
	}

	public void setRolelist(List<Roles> rolelist) {
		this.rolelist = rolelist;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public IUserService getUserservice() {
		return userservice;
	}

	public void setUserservice(IUserService userservice) {
		this.userservice = userservice;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
/**
 * 
 * 
 * 登陆方法
 * 
 * */
	public String userlogin(){
		User u=userservice.userlogin(user);
		HttpSession session =ServletActionContext.getRequest().getSession();
		if(u!=null){
			session.setAttribute("user", u);
			this.setResult("登录成功！");
			session.removeAttribute("flight_s");
			session.removeAttribute("flight_e");
			return "login";
		}else{
			this.setResult("登录失败！");
			return "loginerror";
		}
	}
	
/**
 * 
 * 
 * 注册方法
 * 
 * */
	public String regist(){
	this.user.setRoleId(3);
	boolean b=this.userservice.regist(user);
	if(b==true){
		return "regsuccess";
	}
	return "regerror";	
	}
	/**
	 * 
	 * 
	 * 退出方法
	 * 
	 * */
		public String logout(){
			HttpSession session =ServletActionContext.getRequest().getSession();
			session.removeAttribute("user");
			session.removeAttribute("flight_s");
			session.removeAttribute("flight_e");
		return "logout";	
		}
		
	public String uedit(){
		this.setRolelist(this.userservice.rolelist());
		this.setUlist(this.userservice.ulist());
		return "uedit";
	}	
	public String userrole(){
		this.userservice.userrole(user);
		return "uupdate";
	}
	public String userupdate(){
		this.userservice.userupdate(user);
		return "userupdate";
	}
		
}


